package com.gzsxy.esjy.service.file.configure;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

/**
 * @author xiaolong
 * @version 1.0
 * @description: TODO
 * @date 2021/12/21 16:58
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    private static final String LINUXPATH = "/home/docker-esjy/bin/jar/";

    @Autowired
    private FileProperties fileProperties;

    /**
     * @description: 静态资源路径配置映射
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        //获取系统名
        String os = System.getProperty("os.name");
        //win系统
        if (os.toLowerCase().startsWith("win")){
            String path = System.getProperty("user.dir")  +  File.separator + fileProperties.getUploadPath() + File.separator;
            registry.addResourceHandler("/"+fileProperties.getSystem_id()+"/**").addResourceLocations("file:"+path);
        } else { //linux和mac系统 可以根据逻辑再做处理
            String path = LINUXPATH + fileProperties.getUploadPath()+ File.separator;
            registry.addResourceHandler("/"+fileProperties.getSystem_id()+"/**").addResourceLocations("file:"+ path);
        }



//        String path = System.getProperty("user.dir") + File.separator + fileProperties.getUploadPath() + File.separator;
//        registry.addResourceHandler("/"+fileProperties.getSystem_id()+"/**").addResourceLocations("file:"+path);
//        registry.addResourceHandler("/"+fileProperties.getSystem_id()+"/**").addResourceLocations("file:C:/Users/Lenovo/IdeaProjects/esjy_admin/service/file-server/target/classes/upload/");
    }
}
